<include file="__PUBLIC__/_header" />
<link rel="stylesheet" href="__APP_SKIN__css/product.css"/>

<style type="text/css">
    .am-gallery-default .am-gallery-item img{
     height: 90px;
    }
    .am-gallery-item a{
        display: block;
    }
    .swiper-slide img{
        height: 200px;width: 100%;
    }
    .h-collect{
        display: block;
    }
</style>
<body>
<div class="container">
  	<header data-am-widget="header" class="am-header am-header-default my-header">
        <include file="__PUBLIC__/_header_title" />
        <h1 class="am-header-title">
          <a href="#title-link" class="">商品详情</a>
        </h1>
    </header>

    <!-- banner -->
    <div class="swiper-container">
        <div class="swiper-wrapper h-banner">
            <!--<div class="swiper-slide">slider1</div>-->
            <!--<div class="swiper-slide">slider2</div>-->
            <!--<div class="swiper-slide">slider3</div>-->
        </div>
    </div>
	  <div class="gray-panel">
    	  <div class="paoduct-title-panel">
        	<h1 class="product-h1"></h1>
            <p>
            <span class="bold">价格：</span><span class="red2 h-mianyi">￥<span class="m-price"></span></span>
            </p>

            <p>
             <span class="product-title-gray-text">供应商：<span class="supplier_name"></span></span>
            </p>
        </div>
          <div class="my-search-title-panel">
             <p class="size-p" id="sizep"><span class="m_spec" ></span></p>
              <div class=" h-number clearfix"  style="margin-top: 20px;display: none;">
              <button type="button"  class="h-btn-add" onClick="subtractQty();" >-</button>
              <input type="number" class="h-ge" name="txtQty" id="txtQty" value="1" style=" width:60px; margin-right:0px; height:3rem; display:inline; float:left">
              <button type="button" class="h-btn-sub" style="" onClick="addQty();">+</button>
              </div>

              <div class="h-input"  style="margin-top: 20px;display: none;">
                  <input type="number" value="1" class="h-jin" style=" width:60px; margin-right:0px; height:3rem; display:inline;"> 斤
                  <input type="number" value="1"  class="h-liang" style=" width:60px; margin-right:0px; height:3rem; display:inline;"> 两
                  <input type="number" value="1"  class="h-ke" style=" width:60px; margin-right:0px; height:3rem; display:inline;"> 克
              </div>
          </div>

        <!--<div class="my-search-title-panel">-->
        	<!--<p class="my-search-titp-p am-text-sm bold">宝贝评价(235)</p>-->

          <!--<ul class="am-list am-list-static am-list-border">-->
            <!--<li>-->
              <!--<div class="clearfix">-->
                <!--<img src="img/5.png" width="40" height="40"class=" fl am-img-border am-circle">-->
                <!--<ul class="fl h-start1">-->
                  <!--<li class="h-start2"></li>-->
                  <!--<li></li>-->
                  <!--<li></li>-->
                  <!--<li></li>-->
                  <!--<li></li>-->
                <!--</ul>-->
                <!--<span class="h-gray fr">2015-06-11</span>-->
              <!--</div>-->

              <!--<div class="am-comment-bd h-gray">-->
                  <!--非常好非常好非常好非常好-->
              <!--</div>-->

            <!--</li>-->
            <!--<li>-->
              <!--<a href="" >查看更多</a>-->
            <!--</li>-->
          <!--</ul>-->

        <!--</div>-->

                 <ul data-am-widget="gallery" class="am-gallery am-avg-sm-4 am-avg-md-4 am-avg-lg-4 am-gallery-default h-like"  >


                  </ul>

    </div>


    <!--底部-->
    <div data-am-widget="navbar" class="am-navbar am-cf my-nav-footer " id="">
      <ul class="am-navbar-nav am-cf am-avg-sm-2 my-footer-ul">
        <!--<li>-->
          <!--<a href="/wap/" class="">-->
            <!--<span class="am-share"></span>-->
            <!--<span class="am-navbar-label">分 享</span>-->
          <!--</a>-->
        <!--</li>-->
        <li class="">
          <a href="{:BaseController::_createUrl('order/shopCart')}"  class="">
            <span class=" am-shop2 h-relative">
                <span class="h-num">0</span>
            </span>

            <span class="am-navbar-label">购 物 车</span>
          </a>
        </li>

        <li class="h-red" style="padding: 20px;">
          <a href="javascript:void(0)" class="h-collect" style="display: block;line-height: 50px;">
           加入购物车
          </a>
        </li>

      </ul>

    </div>

    <input type="hidden" value="{:BaseController::getConfig('file_server_url')}/2013/" id="ad_img">
    <input type="hidden" value="{$_GET['kindId']}" id="se_kindId">
    <input type="hidden" value="{:BaseController::_createUrl('index/detail')}/kindId/" id="hidden_url">
    <input type="hidden" value="__APP_SKIN__images/de.jpg" id="hidden_img">
    <input type="hidden" value="{:BaseController::_createUrl('passport/login')}" class="hidden_url2">

</div>

</body>
<script>

    $(function(){
        var fileName=$("#ad_img").val();
        var se_kindId=$("#se_kindId").val();
        var hidden_url=$("#hidden_url").val();
        var hidden_img=$("#hidden_img").val();

        indexHttpHelper.getDetail($(".swiper-wrapper"),fileName,hidden_url,2,se_kindId,hidden_img);
        var mySwiper = new Swiper('.swiper-container', {
            autoplay: 3000,
        })
        $(".h-collect").click(function(){

            var shop_user_id=$(".shop_user_id").val();
            var hidden_url2=$(".hidden_url2").val();
            if(shop_user_id<=0){
                window.location.href=hidden_url2;
                return;
            }
            if($(".m_spec").html()=="斤"){
                var jin=$(".h-jin").val(); var liang=$(".h-liang").val(); var ke=$(".h-ke").val();
                var total=parseInt(jin)*500+parseInt(liang)*50+parseInt(ke);
                var price=$(".m-price").html();
                var total_price=parseFloat(price)*total;
            }else{
                var total=$(".h-ge").val();
                var price=$(".m-price").html();
                var total_price=parseFloat(price)*total;
            }
           var time=new Date().getTime();
//            collectHttpHelper.collect(se_kindId,price,total,time);
            var data='';


            data={
                'groupId':se_kindId,
                'num':total,
                'price':price,
            };
            $.ajax({
                type: 'post',
                url:"{:Controller::_createUrl('index/collect')}",
                dataType: 'text',
                data:data,
                beforSend:function(){

                },
                success: function(data){
                   if(data == 1){
                       $(".h-num").html(parseInt($(".h-num").html())+parseInt(total));
                       alert('添加成功');
                   }else{
                       alert('添加失败');
                   }

                },
                error:function(e){
                    alert('网络错误，请稍后重试');
                }
            });
        })
    })
    function checkIsInteger(str)
    {
        //如果为空，则通过校验
        if(str == "")
            return true;
        if(/^(\-?)(\d+)$/.test(str))
            return true;
        else
            return false;
    }
    var errordialog=function(c){
        alert(c)
    }
    //检验商品数量
    function checkCounts(id) {
        var Counts = $("#" + id).val();
        if (Counts == "") {
            errordialog("请填写数量!");
            return false;
        }
        else if (!checkIsInteger(Counts)) {
            errordialog("商品数量不是整数!");
            return false;
        }
        else if (Counts < 1) {
            errordialog("商品数量不能小于1!");
            return false;
        }
        else {
            return true;
        }
    }
    function addQty(){
        checkCounts('txtQty');
        var qty = parseInt($('#txtQty').val());
        $(".h-num").html(parseInt($(".h-num").html())+1);
        $('#txtQty').val(qty+1);
    }
    function subtractQty(){
        checkCounts('txtQty');
        var qty = parseInt($('#txtQty').val());
        if(qty <=1){
            errordialog("商品数量不能小于1");
            return;
        }
        $(".h-num").html(parseInt($(".h-num").html())-1);
        $('#txtQty').val(qty-1);
    }
</script>
</html>
